import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class test {

	/**
	 * @param args
	 */
	  public static void main(String[] args) {
	 
		  
	 
		   String regexPattern,matchString;
	       
	       while(true){
	    	   
	    	   System.out.println("Enter your regex here : ");
	    	   
	    	   
	    	   Scanner scanIn = new Scanner(System.in);
	    	   
	    	   regexPattern = scanIn.nextLine();
	    	   Pattern pattern = Pattern.compile(regexPattern);
	    	   
	    	   System.out.println("Enter your match here : ");
	    	   matchString = scanIn.nextLine();
	    	   Matcher matcher = pattern.matcher(matchString);
	    	   boolean found = false;
	            while (matcher.find()) {
	                System.out.format("I found the text" +
	                    " \"%s\" starting at " +
	                    "index %d and ending at index %d.%n",
	                    matcher.group(),
	                    matcher.start(),
	                    matcher.end());
	                found = true;
	            }
	            if(!found){
	                System.out.format("No match found.%n");
		       //scanIn.close();
	            }
	       }
	  }
	  }

